import {
  Controller,
  Get,
  Query,
  UseInterceptors,
  Post,
  Request,
  Body,
} from '@nestjs/common';
import { UserService } from './user.service';
import { User } from '../entities/user.entity';
import { TransformInterceptor } from 'src/interceptor/transform.interceptor';

@Controller('user')
@UseInterceptors(TransformInterceptor)
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Get('list')
  findAll(): Promise<User[]> {
    return this.userService.findAll();
  }

  @Get('userById')
  findOne(@Query() query: Record<string, any>): Promise<User> {
    return this.userService.findOne(query.id);
  }

  @Post('add')
  addUser(@Body() body): Promise<User> {
    console.log(body);
    return this.userService.addUser(body);
  }

  @Post('update')
  updateUser(@Body() body): Promise<User> {
    console.log(body);
    return this.userService.updateUser(body);
  }
}
